package it.polimi.traveldream.web.beans;

import it.polimi.traveldream.dtos.UserDTO;
import it.polimi.traveldream.helper.Constants;
import it.polimi.traveldream.managers.UserManager;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class UserBean {
	
	@EJB
	private UserManager userMgr;
	
	private UserDTO loggedUser;
	
	
	
	@PostConstruct
	public void init(){
		if(isUserLogged()){
			loggedUser = userMgr.getLoggedUser();
		}
	}

	


	public UserDTO getLoggedUser(){
		return loggedUser;
	}
	
	public void setLoggedUser(UserDTO loggedUser) {
		this.loggedUser = loggedUser;
	}

	public boolean isUserLogged(){		
		return userMgr.isUserLogged();
	}
	
	
	public String updateUserData(){
		userMgr.updateUser(loggedUser);
		return "/user/index?faces-redirect=true";
	}
	
	

	
}
